package com.xopencode.comparable;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Mcb
 * @date 2022/8/22
 * @apiNote
 */
public class SortDemo {

        public static void main(String[] args) {
            List<Integer> list = Arrays.asList(6, 2, 1, 4, 5, 5);
            sort(list);
            System.out.println(list);
            System.out.println();
            // LocalDate localDate1 = LocalDate.parse("20190912", DateTimeFormatter.BASIC_ISO_DATE);
        }

        /**
         * 排序只有返回1的时候才会交换位置
         * @param list
         */
        public static void sort(List list){
            Collections.sort(list, new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    // int i = o1 - o2; //升序 大于0 换
                    //int i = o2 - o1; //降序 小于0 不换
                    //return i;
                    return  Integer.compare(o1,o2);
                }
            });
        }
}
